﻿package com.urbansquall.echo
{
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	
	/**
	 * Allows you to play sounds from a particular SoundGroup.
	 * @author Marshall Powers
	 */
	public class GroupedSound 
	{
		private var m_group : SoundGroup;
		private var m_sound : Sound;
		private var m_defaultVolume : Number;
		
		public function GroupedSound(a_group : SoundGroup, a_sound : Sound, a_defaultVolume : Number = 1.0) 
		{
			m_group = a_group;
			m_sound = a_sound;
			m_defaultVolume = a_defaultVolume;
		}
		
		public function play(a_startTime : int = 0, a_loops : int = 0, a_transform : SoundTransform = null) : ChannelWrapper
		{
			var channel : SoundChannel = m_sound.play(a_startTime, a_loops, a_transform);
			var wrap : ChannelWrapper = null;
			if (channel != null)
			{
				wrap = new ChannelWrapper(channel);
				m_group.addChild(wrap);
				wrap.localVolume = m_defaultVolume
			}
			
			return wrap;
		}
		
		public function get group() : SoundGroup
		{
			return m_group;
		}
		
		public function get sound() : Sound
		{
			return m_sound;
		}
		
		public function get defaultVolume() : Number
		{
			return m_defaultVolume;
		}
		
		public function set defaultVolume(a_value : Number) : void
		{
			m_defaultVolume = a_value
		}
	}
}